home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / arrow.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  122 lines

  1. ; $Id: arrow.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2.  
  3. ;
  4. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  5. ;    Unauthorized reproduction prohibited.
  6. ;
  7. PRO ARROW, x0, y0, x1, y1, HSIZE = hsize, COLOR = color, HTHICK = hthick, $
  8.     THICK = thick, DATA = data, DEVICE = device, NORMALIZED = norm, $
  9.     SOLID = solid
  10. ;+
  11. ; NAME:                ARROW
  12. ; PURPOSE:    Draw a vector(s) with an arrow head
  13. ; CATEGORY:    Graphics
  14. ; CALLING SEQUENCE:
  15. ;    ARROW, x0, y0, x1, y1
  16. ; INPUTS:
  17. ;    (x0, y0) = coordinates of beginning of vector(s).  May be arrays
  18. ;        or scalars. Coordinates are in DEVICE coordinates
  19. ;        unless otherwise specified.
  20. ;    (x1, y1) = coordinates of endpoint (head) of vector.  
  21. ;        x0, y0, x1, y1 must all have the same number of elements.
  22. ; KEYWORD PARAMETERS:
  23. ;    DATA - if set, implies that coordinates are in data coords.
  24. ;    NORMALIZED - if set, coordinates are specified in normalized coords.
  25. ;    HSIZE = size of arrowhead.  Default = 1/64th the width of the device,
  26. ;        (!D.X_SIZE / 64.).
  27. ;        If the size is positive, it is assumed to be in device
  28. ;        coordinate units.  If it is NEGATIVE, then the head length
  29. ;        is set to the vector length * abs(hsize), giving heads
  30. ;        proportional in size to the bodies.  The size is defined as
  31. ;        the length of each of the lines (separated by 60 degrees) 
  32. ;        that make the head.
  33. ;    COLOR = drawing color.  Default = highest color index.
  34. ;    HTHICK = thickness of heads.  Default = 1.0.
  35. ;    SOLID = if set, make a solid arrow, using polygon fills, looks better
  36. ;        for thick arrows.
  37. ;    THICK = thickness of body.    Default = 1.0.
  38. ;    
  39. ; OUTPUTS:
  40. ;    No explicit outputs.
  41. ; SIDE EFFECTS:
  42. ; RESTRICTIONS:
  43. ; PROCEDURE:
  44. ;    Straightforward.
  45. ;    Examples:
  46. ;          Draw an arrow from (100,150) to (300,350) in DEVICE units.
  47. ;    ARROW, 100, 150,  300, 350
  48. ;
  49. ;        Draw a sine wave with arrows from the line Y=0 to
  50. ;        sin(x/4).
  51. ;    X = FINDGEN(50)
  52. ;    Y = SIN(x/4)        ;Make sin wave
  53. ;    PLOT, X, Y
  54. ;    ARROW, X, REPLICATE(0,50), X, Y, /DATA
  55. ; MODIFICATION HISTORY:
  56. ;    DMS, Feb, 1992.
  57. ;    DMS, Sept, 1992.  Added /SOLID.
  58. ;-
  59.  
  60. ;  Draw an arrow with a head from (x0,y0) to (x1, y1).  Params may be
  61. ;        vectors.
  62.  
  63. ;  Set up keyword params
  64.  
  65. if n_elements(thick) eq 0 then thick = 1.
  66. if n_elements(hthick) eq 0 then hthick = thick
  67.  
  68.                 ;Head size in device units
  69. if n_elements(hsize) eq 0 then arrowsize = !d.x_size/64. * (hthick/2. > 1) $
  70.     else arrowsize = float(hsize)
  71. if n_elements(color) eq 0 then color = !P.color
  72.  
  73. mcost = -.866        ;We use 30 degrees for head angle
  74. sint = .500
  75. msint = - sint
  76.  
  77. for i = 0, n_elements(x0)-1 do begin        ;Each vector
  78.     if keyword_set(data) then $        ;Convert?
  79.         p = convert_coord([x0[i],x1[i]],[y0[i],y1[i]], /data, /to_dev) $
  80.     else if keyword_set(norm) then $
  81.         p = convert_coord([x0[i],x1[i]],[y0[i],y1[i]], /norm, /to_dev) $
  82.     else p = [[x0[i], y0[i]],[x1[i], y1[i]]]
  83.  
  84.     xp0 = p[0,0]
  85.     xp1 = p[0,1]
  86.     yp0 = p[1,0]
  87.     yp1 = p[1,1]
  88.  
  89.     dx = float(xp1-xp0)
  90.     dy = float(yp1-yp0)
  91.     zz = sqrt(dx^2 + dy^2)    ;Length
  92.  
  93.     if zz gt 1e-6 then begin
  94.         dx = dx/zz        ;Cos th
  95.         dy = dy/zz        ;Sin th
  96.     endif else begin
  97.         dx = 1.
  98.         dy = 0.
  99.         zz = 1.
  100.     endelse
  101.     if arrowsize gt 0 then a = arrowsize $  ;a = length of head
  102.     else a = -zz * arrowsize
  103.  
  104.     xxp0 = xp1 + a * (dx*mcost - dy * msint)
  105.     yyp0 = yp1 + a * (dx*msint + dy * mcost)
  106.     xxp1 = xp1 + a * (dx*mcost - dy * sint)
  107.     yyp1 = yp1 + a * (dx*sint  + dy * mcost)
  108.  
  109.     if keyword_set(solid) then begin    ;Use polyfill?
  110.       b = a * mcost*.9    ;End of arrow shaft (Fudge to force join)
  111.       plots, [xp0, xp1+b*dx], [yp0, yp1+b*dy], /DEVICE, $
  112.         COLOR = color, THICK = thick
  113.       polyfill, [xxp0, xxp1, xp1, xxp0], [yyp0, yyp1, yp1, yyp0], $
  114.         /DEVICE, COLOR = color
  115.     endif else begin
  116.       plots, [xp0, xp1], [yp0, yp1], /DEVICE, COLOR = color, THICK = thick
  117.       plots, [xxp0,xp1,xxp1],[yyp0,yp1,yyp1], /DEVICE, COLOR = color, $
  118.             THICK = hthick
  119.     endelse
  120.     ENDFOR
  121. end
  122.